#include "sdlengine.hpp"

using namespace sdl_engine;
using namespace sdl_engine::unit_test;

class TestTileSheet: public Test, public App {
public:
    void SetUp() override {
        engine.SetApp(this);
        tileSheet_ = std::make_unique<TileSheet>("assets/tilesheet.bmp",
                                                 28, 20, color(0, 0, 0));
    }

    void Render(Renderer& renderer) override {
        for (int x = 0; x < 20; x++) {
            for (int y = 0; y < 28; y++) {
                auto tile = tileSheet_->Get(x, y);
                renderer.RenderCopy(&tile,
                                    point(x * tile.GetSize().w,
                                          y * tile.GetSize().h));
                auto tile2 = tileSheet_->Get(x + y * 20);
                renderer.RenderCopy(&tile2,
                                    point(x * tile2.GetSize().w + 350,
                                          y * tile2.GetSize().h));
            }
        }
    }

    void Run() override {
        RUN_ENGINE();
    }

private:
    Unique<TileSheet> tileSheet_ = nullptr;
};

int main(int argc, char** argv) {
    Window::CreateInfo createInfo;
    createInfo.SetSize(size(720, 480));
    createInfo.SetTitle("test tilesheet");

    engine.Init(argc, argv, createInfo, Renderer::CreateInfo());

    auto test = new TestTileSheet;

    unittest.RegistTest(test);
    unittest.AddTest(test);

    unittest.RunTests();

    engine.Shutdown();
    return 0;
}
